<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">查看试卷</a>
        <a>
          <cite>查看试卷</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="teaNo"  placeholder="请输入试卷编号" id="teaNo" autocomplete="off" class="layui-input" style="width: 160px;">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="search" id="searchByNo" value="搜索"
                   onclick="searchTeaByNo()"/>
            <input type="text" name="teaName"  placeholder="请输入试卷名称" id="teaName" autocomplete="off" class="layui-input">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="search" id="searchByName" value="搜索"
                   onclick="searchTeaByName()"/>
            <input type="text" name="teaDl"  placeholder="请输入试卷类型" id="teaDl" autocomplete="off" class="layui-input" style="width: 160px;">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="search" id="searchByDis" value="搜索"
                   onclick="searchTeaByDl()"/>
            <br><br>
            <input type="button" class="layui-btn" id="showAll" onclick="showAllTea()" value="查看所有"/>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加试卷','./testAdd.html')"><i class="layui-icon"></i>添加</button>
<!--        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        <span class="x-right" style="line-height:40px">本次搜索总共搜索到<b><font size="4px" color="red" id="number">这里填入搜索结果的统计数量</font></b>条数据</span>
    </xblock>
    </xblock>
    <table class="layui-table">
        <thead >
        <tr>
<!--            <th width="4%">-->
<!--                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>-->
<!--            </th>-->
            <th width="11%">试卷编号</th>
            <th>试卷名称</th>
            <th width="20%">试卷创立时间</th>
            <th width="7%">试卷类型</th>
            <th width="7%">题目数量</th>
            <th width="7%">难易程度</th>
            <th width="7%">试卷满分</th>
            <th width="18%">查看或修改试卷详情</th>
        </tr>
        </thead>
        <tbody id="testList">
        <tr id="test"></tr>
        <td class="td-status" id="button"></td>
        <tr id="test0">
<!--            <td>-->
<!--                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>-->
<!--            </td>-->
            <td id="testNo0"></td>
            <td id="testName0"></td>
            <td id="testTime0"></td>
            <td id="testType0"></td>
            <td id="testNum0"></td>
            <td id="testDif0"></td>
            <td id="testScore0"></td>
            <td class="td-status" id="button0">
                <a title="查看" id="show0" onclick="x_admin_show_sendId(this.title,'testDetailsTea.html',700,600)" href="javascript:;">
                    <button class="layui-btn">查看</button>
                </a>
                <a title="修改" id="change0" onclick="x_admin_show_sendId(this.title,'testChange.html')" href="javascript:;">
                    <button  class="layui-btn layui-btn-warm" >修改</button>
                </a>
                <a title="删除"  id="delete0" onclick="member_del(this,this.title)" href="javascript:;">
                    <button class="layui-btn layui-btn-danger">删除</button>
                </a>
            </td>
        </tr>
        </tbody>
    </table>


</div>

<input id="Id" type="hidden" name="tstNo" value="">

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });
</script>

<script type="text/javascript">
    $("#Id").val(sessionStorage.getItem("teaId"));
    $.ajax({
        url: "/exam/queryall",
        type : "post",
        async: false,
        dataType: "json",
        data :null,
        // contentType: "application/json",
        success: function (data) {
            console.log("请求成功");
            console.log(data);
            var i=0;
            for (;;i++){
                if (data[i]){
                    if (i!==0){
                        var test=document.getElementById("test").cloneNode();

                        var tstNo=document.getElementById("testNo0").cloneNode(true);
                        var tstName=document.getElementById("testName0").cloneNode(true);
                        var tstTime=document.getElementById("testTime0").cloneNode(true);
                        var tstType=document.getElementById("testType0").cloneNode(true);
                        var tstNum=document.getElementById("testNum0").cloneNode(true);
                        var tstDif=document.getElementById("testDif0").cloneNode(true);
                        var tstScore=document.getElementById("testScore0").cloneNode(true);

                        tstNo.innerHTML=data[i].tstNo;
                        tstName.innerHTML=data[i].tstName;
                        tstTime.innerHTML=data[i].tstTime;
                        tstType.innerHTML=data[i].tstType;
                        tstNum.innerHTML=data[i].tstNum;
                        tstDif.innerHTML=data[i].tstDif;
                        tstScore.innerHTML=data[i].tstScore;

                        test.appendChild(tstNo);
                        test.appendChild(tstName);
                        test.appendChild(tstTime);
                        test.appendChild(tstType);
                        test.appendChild(tstNum);
                        test.appendChild(tstDif);
                        test.appendChild(tstScore);
                        var button=document.getElementById("button").cloneNode(true);
                        var show=document.getElementById("show0").cloneNode(true);
                        var change=document.getElementById("change0").cloneNode(true);
                        var del=document.getElementById("delete0").cloneNode(true);
                        show.title=data[i].tstNo;
                        change.title=data[i].tstNo;
                        del.title=data[i].tstNo;
                        button.appendChild(show);
                        button.appendChild(change);
                        button.appendChild(del);
                        test.appendChild(button);

                        document.getElementById("testList").appendChild(test);
                        var j=i+1;
                        document.getElementById("number").innerHTML=j;
                    }
                    else if (i==0){
                        document.getElementById("show0").title=data[0].tstNo;
                        document.getElementById("change0").title=data[0].tstNo;
                        document.getElementById("delete0").title=data[0].tstNo;
                        document.getElementById("testNo0").innerHTML=data[0].tstNo;
                        document.getElementById("testName0").innerHTML=data[0].tstName;
                        document.getElementById("testTime0").innerHTML=data[0].tstTime;
                        document.getElementById("testType0").innerHTML=data[0].tstType;
                        document.getElementById("testNum0").innerHTML=data[0].tstNum;
                        document.getElementById("testDif0").innerHTML=data[0].tstDif;
                        document.getElementById("testScore0").innerHTML=data[0].tstScore;
                    }
                }
                else break;
            }
        },
        error: function (data) {
            console.log("请求失败");
        }
    });
</script>


<script>
    /*用户-删除*/
    function member_del(obj,id){

        $.ajax({
            url: "/exam/delete",
            type : "post",
            async: false,
            dataType: "json",
            data : {tstNo:id},

            success: function (data) {
                console.log('请求成功');
                if (data==1){
                    $(obj).parents("tr").remove();
                    alert("删除成功");}
                else alert("删除失败");
            },
            error: function (data) {
                console.log("请求失败");
            }
        });

    }



    function delAll (argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
</body>

</html>